package com.achao.achaomq.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * 公共工具类
 */
public class CommonUtils extends BeanUtils {

    //copy集合对外暴露工具
    public static <S,T> List<T> copyPropertiesToList(List<S> sources, Supplier<T> target){
        return copyList(sources,target);
    }

    //copy集合具体步骤
    private static <S,T> List<T> copyList(List<S> sources, Supplier<T> target){
        List<T> list = new ArrayList<>(sources.size());
        for(S source : sources){
            T t = target.get();
            copyProperties(source,t);
            list.add(t);
        }
        return list;
    }

}
